package com.yingside.collection.homework;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Test6 {
    public static void main(String[] args) {
        Map<Integer,String> map = new HashMap<Integer, String>();
        map.put(1, "张三丰");
        map.put(2, "周芷若");
        map.put(3, "赵敏");
        map.put(4, "灭绝师太");
        map.put(5,"李晓红");

        map.remove(1);

        map.put(2,"张无忌");
        //得到所有的键
        /*Set<Integer> keys = map.keySet();

        for (Integer key : keys) {
            System.out.println(key + "===" + map.get(key));
        }*/

        //上面的方式是通过键得到值，其实map还可以直接把键值循环出来

        //map的键值对，其实是存放在Map内部的一个内部类Entry当中的
        Set<Map.Entry<Integer, String>> entries = map.entrySet();

        Iterator<Map.Entry<Integer, String>> iterator = entries.iterator();

        while(iterator.hasNext()){
            Map.Entry<Integer, String> next = iterator.next();
            Integer key = next.getKey();
            String value = next.getValue();

            System.out.println("key = " + key);
            System.out.println("value = " + value);
        }



    }
}
